package com.card.hwatt.assembler;

import java.util.ArrayList;
import java.util.List;

import com.card.hwatt.core.ObjectUtil;
import com.card.hwatt.dto.PageResult;
import com.card.hwatt.entity.*;

public final class OvertimeAssembler {

	public static PageResult<com.card.hwatt.dto.Overtime> convert(
			PageResult<Overtime> list) {
		PageResult<com.card.hwatt.dto.Overtime> rows = new PageResult<com.card.hwatt.dto.Overtime>();
		rows.rows = new ArrayList<com.card.hwatt.dto.Overtime>();
		rows.total = list.total;
		for (Overtime item : list.rows) {
			com.card.hwatt.dto.Overtime dto = convert(item);
			rows.rows.add(dto);
		}
		return rows;
	}

	public static List<com.card.hwatt.dto.Overtime> convert(List<Overtime> list) {
		List<com.card.hwatt.dto.Overtime> rows = new ArrayList<com.card.hwatt.dto.Overtime>();
		for (Overtime item : list) {
			com.card.hwatt.dto.Overtime dto = convert(item);
			rows.add(dto);
		}
		return rows;
	}

	public static com.card.hwatt.dto.Overtime convert(Overtime entity) {
		com.card.hwatt.dto.Overtime dto = new com.card.hwatt.dto.Overtime();
		ObjectUtil.fieldCopy(entity, dto);

		dto.startCardId = entity.startCard.id;
		dto.startCardDate = entity.startCard.date;

		dto.endCardId = entity.endCard.id;
		dto.endCardDate = entity.endCard.date;

		dto.employeeId = entity.employee.id;
		dto.employeeCode = entity.employee.employeeCode;
		dto.employeeName = entity.employee.name;
		dto.departmentName = entity.employee.department.name;
		return dto;
	}

	public static Overtime convert(com.card.hwatt.dto.Overtime dto) {
		Overtime entity = new Overtime();
		ObjectUtil.fieldCopy(dto, entity);

		entity.startCard = new Card();
		entity.startCard.id = dto.startCardId;

		entity.endCard = new Card();
		entity.endCard.id = dto.endCardId;

		entity.employee = new Employee();
		entity.employee.id = dto.employeeId;

		return entity;
	}
}
